package com.xuecheng.controller;

import com.xuecheng.model.dto.CheckCodeParamsDTO;
import com.xuecheng.model.vo.CheckCodeResultVO;
import com.xuecheng.service.CheckCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 验证码服务接口
 */
@Slf4j
@Api(value = "验证码服务接口")
@RestController
public class CheckCodeController {
	
	@Resource(name = "PicCheckCodeService")
	private CheckCodeService picCheckCodeService;
	
	
	@ApiOperation(value = "生成验证信息", notes = "生成验证信息")
	@PostMapping(value = "/pic")
	public CheckCodeResultVO generatePicCheckCode(CheckCodeParamsDTO checkCodeParamsDTO) {
		log.info("生成验证信息:{}", checkCodeParamsDTO);
		return picCheckCodeService.generate(checkCodeParamsDTO);
	}
	
	@ApiOperation(value = "校验", notes = "校验")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "name", value = "业务名称", required = true, dataType = "String", paramType = "query"),
		@ApiImplicitParam(name = "key", value = "验证key", required = true, dataType = "String", paramType = "query"),
		@ApiImplicitParam(name = "code", value = "验证码", required = true, dataType = "String", paramType = "query")
	})
	@PostMapping(value = "/verify")
	public Boolean verify(String key, String code) {
		log.info("校验:{}", key + ":" + code);
		return picCheckCodeService.verify(key, code);
	}
}
